﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using GMAC.ReportingSystem.Business.Entities;
using System.Data;
using Microsoft.Reporting.WebForms;

namespace GMAC.ReportingSystem.Paginas
{
    public partial class ReporteGerencial : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Se verifica que el usuario haya iniciado sesión
            if (!User.Identity.IsAuthenticated || Session["User"] == null)
            {
                System.Web.Security.FormsAuthentication.RedirectToLoginPage();
                return;
            }
            if (IsPostBack) return;
            Initialize();
            ValidateSecurity();

           
        }
        public void Initialize()
        {
            if (!this.IsPostBack)
            {


                grvProductType.DataSource = GenerateDataTablePrueba();
                grvProductType.DataBind();

                this.ddlProductTypeIC.Items.Add(new ListItem("Banco de Venezuela", "3"));
                this.ddlProductTypeIC.Items.Add(new ListItem("GMAC", "2"));
                this.ddlProductTypeIC.Items.Insert(0, new ListItem("Select...", String.Empty));
                txtRDateSearch.Text = DateTime.Now.ToString("dd/MM/yyyy"); 
               

            }
        }
        private void ValidateSecurity()
        {
            //var beEntities = ((User)Session["User"]).Role.Security.GetEntitySecurity("User");
            //if (beEntities == null) return;
            //if (!beEntities.CanRead)
            //{
            //    grvUsers.Visible = false;
            //    btnModify.Visible = false;
            //    btnDelete.Visible = false;
            //    pnlSearch.Visible = false;
            //}
            //if (!beEntities.CanWrite)
            //{
            //    btnSave.Visible = false;
            //}
            //if (!beEntities.CanInsert)
            //{
            //    btnNew.Visible = false;
            //    btnCancel.Visible = false;
            //    pnlEdit.Visible = false;
            //}
            //if (!beEntities.CanDelete)
            //{
            //    btnDelete.Visible = false;
            //}
        }

        protected void imgBuscarReg_Click(object sender, ImageClickEventArgs e)
        {
            //List<ReportParameter> parametros = new List<ReportParameter>();
            //parametros.Add(new ReportParameter("Type", this.ddlType.SelectedValue));
            //parametros.Add(new ReportParameter("EstatusStr", this.ddlEstatus.SelectedItem.Text));
            //parametros.Add(new ReportParameter("Placa", this.txtPlaca.Text));
            //if (String.IsNullOrEmpty(this.ddlCliente.SelectedValue))
            //{
            //    parametros.Add(new ReportParameter("IdCliente", "0"));
            //}
            //else
            //{
            //    parametros.Add(new ReportParameter("IdCliente", this.ddlCliente.SelectedValue));
            //}
            //parametros.Add(new ReportParameter("Cliente", this.ddlCliente.SelectedItem.Text));
            //string FechaDesde = null;
            //if (string.IsNullOrEmpty(this.txtFechaDesde.Text))
            //{
            //    parametros.Add(new ReportParameter("FechaDesde", FechaDesde));
            //}
            //else
            //{
            //    parametros.Add(new ReportParameter("FechaDesde", this.txtFechaDesde.Text));
            //}
            //string FechaHasta = null;
            //if (string.IsNullOrEmpty(this.txtFechaHasta.Text))
            //{
            //    parametros.Add(new ReportParameter("FechaHasta", FechaHasta));
            //}
            //else
            //{
            //    parametros.Add(new ReportParameter("FechaHasta", this.txtFechaHasta.Text));
            //}

            //string asignacion = null;
            //if (!String.IsNullOrEmpty(this.txtAsignacion.Text.Trim()))
            //{
            //    asignacion = this.txtAsignacion.Text;
            //}
            //parametros.Add(new ReportParameter("Asignacion", asignacion));

            //string localizacion = null;
            //if (!String.IsNullOrEmpty(this.txtLocGeografica.Text.Trim()))
            //{
            //    localizacion = this.txtLocGeografica.Text;
            //}
            //parametros.Add(new ReportParameter("LocalizacionGeo", localizacion));


            //this.rptwReportes.Style.Add("margin-bottom", "26px");
            //this.rptwReportes.ServerReport.ReportPath = "/ReportSIT/rptServicios";
            //this.rptwReportes.ProcessingMode = ProcessingMode.Remote;
            //this.rptwReportes.ServerReport.ReportServerUrl = new Uri(ConfigurationManager.AppSettings["REPORT_SERVER"].ToString());
            //this.rptwReportes.ServerReport.SetParameters(parametros);
            Image1.Visible = true;
        }

        private DataTable GenerateDataTablePrueba()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("AccountTypeID", typeof(string));
            dt.Columns.Add("ProductName", typeof(string));
            DataRow rowdt;
            rowdt = dt.NewRow();
            rowdt[0] = "2";
            rowdt[1] = "GMAC";
            dt.Rows.Add(rowdt);
            rowdt = dt.NewRow();
            rowdt[0] = "3";
            rowdt[1] = "Banco de Venezuela";
            dt.Rows.Add(rowdt);
            rowdt = dt.NewRow();
            rowdt[0] = "4";
            rowdt[1] = "Otro Producto";
            dt.Rows.Add(rowdt);

            return dt;

        }

    }
}
